<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>原力防护</title>
	<link rel="stylesheet" href="/static/css/bootstrap.min.css" />
	<link rel="stylesheet" href="/static/css/header.css" />
	<link rel="stylesheet" href="/static/css/style.css" />
	 <!-- jquery-ui CSS -->
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
    <!-- standard jqGrid CSS -->
    <link rel="stylesheet" href="/static/css/ui.jqgrid.css">

    <!-- jqGrid CCS override -->
  	<link rel="stylesheet" href="/static/css/jqGrid.bootstrap.css">
	
</head>
<body>
	<div class="warp">
		<div class="nav_box">
            <div id="wrap">
                <div id="topBar">
                    <div class="nav clearfix" id="nav">
                        <div class="topBar">
                            <div class="nav_cont clearfix">
                                <a href="http://www.semyes.cn/index.php/Home/Index/index.html" class="nav_Logo"> <img src="../img/logo.png" /></a>
                                <ul class="nav_list clearfix">
                                    <li class="nav_list_li">
                                        <a class="active" href="http://www.semyes.cn/index.php/Home/Index/index.html" target="_self" >首页</a>
                                    </li>
                                    <li class="nav_list_li">
                                        <a class="" href="http://www.semyes.cn/index.php/Home/Yishubao/index.html" target="_self">易数宝</a>
                                    </li>
                                    <li class="nav_list_li">
                                        <a href="http://www.semyes.cn/index.php/Home/Fwxm/index.html" target="" class="">服务项目</a>
                                        <ul class="subnav">
                                            <li>
                                                <a href="http://www.semyes.cn/index.php/Home/Fwxm/sem.html" target="_self">SEM</a>
                                            </li>
                                            <p class="subnav_Tri"></p>
                                            <li>
                                                <a href="http://moban.semyes.cn" target="_self">网站建设</a>
                                            </li>
                                    
                                            <p class="subnav_Tri"></p>
                                    <li ><a href="http://www.semyes.cn/index.php/Home/Fwxm/extension.html"  target="_self">信息流广告</a></li><p class="subnav_Tri"></p>
                                        </ul>
                                    </li>
                                    <li class="nav_list_li">
                                        <a href="http://www.semyes.cn/index.php/Home/Project/index.html" target="_self">成功案例</a>
                                    </li>
                                    <li class="nav_list_li">
                                        <a href="join.semyes.cn" target="_self">招商加盟</a>
                                    </li>
                                    <li class="nav_list_li">
                                        <a href="http://www.semyes.cn/index.php/Home/Contact/index.html" target="_self" class="">联系我们</a>
                                    </li>
                                    <li class="nav_list_li">
                                        <a href="http://www.semyes.cn/index.php/Home/Auto/introduce.html" target="_self" class="">关于我们</a>
                                        <ul class="subnav">
                                            <li>
                                                <a href="http://www.semyes.cn/index.php/Home/Auto/introduce.html" target="_self">原昇介绍</a>
                                            </li>
                                            <p class="subnav_Tri"></p>
                                            <li>
                                                <a href="http://www.semyes.cn/index.php/Home/Auto/culture.html" target="_self">原昇文化</a>
                                            </li>
                                            <p class="subnav_Tri"></p>
                                        </ul>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<div class="content">
			<ul class="step">
				<li class='c8b'>
					<img src="../img/entrench.png" class="img-ico">
					<a href="/home/index.do">防护状态</a>
				</li>
				<!-- <li class="c4c c8b">
					<img src="img/monitoring.png" class="img-ico">
					<a href="page/monitoring_journal.html">监控日志</a>
				</li> -->
				<li class="c8b present">
					<img src="../img/generalize.png" class="img-ico">
					<a href="/visitor/index.do">访客管理</a>
				</li>
				<!-- <li class="c75">
					<img src="../img/crux.png" class="img-ico">
					<a href="page/crux_intercept.html">关键词拦截</a>
				</li> -->
				<li  class="record c89 ">
					<img src="../img/set.png" class="img-ico">
					<a href="/configure/index.do">防火墙设置</a>
				</li>
			</ul>


		<div class="middle-content" >
				<div class="sdt_firewallcon clear-float">
					<div class="sdt_thead"></div>
					<div class="Shared_form">
						<span>
							<a href="javascript:void(0)" onclick="getTodayIpData()">今天</a>
						</span>
						<span><a href="javascript:void(0)" onclick="getYesterdayIpData()">昨天</a></span>
						
						<span style="display:none"> IP:</span>
						<input style="display:none" type="text" class="text-box sdt_listin">

						<span>时间：<input type="text" id="begin" class="text-box sdt_listin laydate-icon date-input" value="2017-10-01"> 至  <input type="text" id="finish" class="text-box sdt_listin laydate-icon date-input data-left" value="2017-10-07"></span>

						<input type="button" value="查询" class="inp_cx">
						<input type="button" value="生成Excel" class="btnExportExcel">
					</div>
					 <div class="content">

					      <table id="contentList"></table>
					      <div id="contentListPager"></div>
					
					   </div><!-- /.container -->
					
					<div class="tips-bg">
						<fieldset class="tips">
							<legend>小贴士：</legend>
							<p>1.管理访客的访问情况。</p>
							<p>2.可以手动调整访客的属性。</p>
							<p>3.访客IP最早统计到昨天的数据。</p>
							<p>4.访客IP添加到百度IP排除列表后则此IP点击推广不收费。</p>
						</fieldset>
					</div>
				</div>
				
			</div>
		</div>
		
	</div>
	<iframe src="../footer/footer.html" height="135px" width="100%" frameborder="0"></iframe>
	<!-- loding -->
    <div class="fied">
        <img src="../img/load.gif">
        <div class="calculate-middle">正在处理中</div>
    </div>
</body>

<script type="text/javascript" src="/static/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/laydate.dev.js"></script>
<script src="/static/js/JsonExportExcel.min.js"></script>
<!-- jQuery -->
  
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

    <!-- jqGrid -->
    <script src="/static/js/grid.locale-cn.js"></script>
    <script src="/static/js/jquery.jqGrid.min.js"></script>

    <script>
   
      $(function() {
    	  		$(".fied").hide();
    			var begintime = laydate.now(-165);
    			var finishtime = laydate.now();
    			
    			document.getElementById("begin").value = begintime;
    			document.getElementById("finish").value = finishtime;
    			
    			getList(begintime, finishtime);
 
    			laydate({
    				elem: document.getElementById('begin'),
    				format: 'YYYY-MM-DD', // 分隔符可以任意定义,只显示年月日
    				min:"2015-01-01",
    				choose: function(datas){ //选择日期完毕的回调
    					begintime = datas;
    			    }});
    			laydate({
    				elem: document.getElementById('finish'),
    				format: 'YYYY-MM-DD', // 分隔符可以任意定义,只显示年月日
    				choose: function(datas){ //选择日期完毕的回调
    					finishtime = datas;
    					
    			    }});
    			
    			$(".inp_cx").click(function(){
    				//刷新页面
    				$("#contentList").setGridParam({url:'/visitor/getIpData.do?yesterday=' + finishtime
    			        + '&oneweekago=' + begintime}).trigger("reloadGrid");
    			        			    
    			});		
    			
    			$(".btnExportExcel").click(function() {
    				$(".fied").show();
    				$.ajax({
    			      	type: "GET",      //data 传送数据类型。post 传递
    			      	dataType: 'json',  // 返回数据的数据类型json
    			      	url: '/visitor/dowloadExcel.do?yesterday=' + finishtime + '&oneweekago=' + begintime,  // 
    			      	error:function(){
    			         	alert("数据传输错误");
    			      	},success: function (json) {
    			      		console.log(json);
    			      		$(".fied").hide();
    			      		
    			      		var option = {};
    			      		option.fileName = GenNonDuplicateID(3).toString()
    			      		option.datas = [{
    			      		        sheetData: json.data,
    			      		        sheetName: 'IP数据',
    			      		        sheetFilter: ['mip','mcount','mstartTime','mendTime','mtotalSecond','miparea','maddornot'],
    			      		        sheetHeader: ['IP', '次数', '访问开始时间', '访问结束时间', '停留时间(s)', '地域', '状态'],
    			      		    },
    			      		  	{
    			      		      sheetData:json.data
    			      		    }
    			      		];
    			      		var toExcel = new ExportJsonExcel(option);
    			      		toExcel.saveExcel();

    			        }
    			      
    				})       
    			});
    		
      });
        
      function getList(begintime, finishtime) {
    	 $("#contentList")
			.jqGrid(
					{
						url : '/visitor/getIpData.do?yesterday=' + finishtime + '&oneweekago=' + begintime,
						datatype : "json",
						colModel : [
								{
									label : 'IP',
									name : 'mip',
									width : 40,
									key : true,
									align:"center"
								},
								{
									label : '次数',
									name : 'mcount',
									width : 13,
									align:"center"
								},
								{
									label : '访问开始时间',
									name : 'mstartTime',
									width : 48,
									align:"center"

								},
								{
									label : '访问结束时间',
									name : 'mendTime',
									width : 48,
									align:"center"

								}, {
									label : '停留时间(s)',
									name : 'mtotalSecond',
									width : 28,
									align:"center"
								}, {
									label : '地域',
									name : 'miparea',
									width : 45,
									align:"center"
								}, {
									label : '状态',
									name : 'maddornot',
									index : 'maddornot',
									width : 18,
									align:"center"
								},{

									label : '操作',
									name : 'uploadContentBt',
									width : 57,
									align:"center"
								} ],
						viewrecords : true,
						height : 370,
						rowNum : 10,
						
						rownumbers : true,
						rownumWidth : 25,
						autowidth : true,
						multiselect : true,						
						pager : "#contentListPager",
						jsonReader : {
							root : "page.list",
							page : "page.currPage",
							total : "page.totalPage",
							records : "page.totalCount"
						},
						prmNames : {
							page : "page",
							rows : "limit",
							order : "order"
						},
						gridComplete : function() {
							
							var ips = jQuery("#contentList").jqGrid(
									'getDataIDs');
							var obj = jQuery("#contentList").jqGrid("getRowData");

							// console.log("总记录数:"+ips.length);
							for (var i = 0; i < ips.length; i++) {
								
								var cl = ips[i];
								console.log(ips[i]);
								console.log("总长度："+ips.length);
								console.log(obj[i]);
								if (obj[i].maddornot == "已添加") {
									
									var uploadContent =  "<button type=\"button\" class=\"btn btn-danger\" onclick='delip(\""+
									cl+"\",\""+begintime+"\",\"" +finishtime+"\")' style=\"margin-left: 5px\"><i class=\"fa fa-location-arrow\"></i>&nbsp;从百度ip排除列表删除</button>";
										
								} else if (obj[i].maddornot == "未添加"){
									var uploadContent = "<button type=\"button\" class=\"btn btn-primary\" onclick='addip(\""+
									cl+"\",\""+begintime+"\",\"" +finishtime+"\")' style=\"margin-left: 5px\"><i class=\"fa fa-location-arrow\"></i>&nbsp;添加到百度ip排除列表</button>";									
									
								}
								
								jQuery("#contentList").jqGrid('setRowData',
										ips[i], {
											uploadContentBt : uploadContent,

										});
							}
						}
					});
    	 
      } 
      
      function addip(ip, begintime, finishtime){
      	  
      		$(".fied").show();
      	  	$.ajax({
    	      	type: "GET",      //data 传送数据类型。post 传递
    	      	dataType: 'json',  // 返回数据的数据类型json
    	      	url: "/visitor/update.do?addordel=1&excludeIp=" + ip,  // 
    	      	//data: {tel: tel},  //传送的数据
    	      	error:function(){
    	         	alert("数据传输错误");
    	      	},success: function (json) {
    	      		console.log(json);
    	      		if (json.data == 1) {
    	      			alert("添加成功！");
    	      			$(".fied").hide();
    	      			reloadTable(begintime,finishtime);
    	      		}  else {
    	      			alert("添加失败！");
    	      			
    	      		}
    	         	
    	        } 
    		})         
        }
      
        function delip(ip, begintime, finishtime){
      	  
      		$(".fied").show();
    	  	$.ajax({
    	      	type: "GET",      //data 传送数据类型。post 传递
    	      	dataType: 'json',  // 返回数据的数据类型json
    	      	url: "/visitor/update.do?addordel=0&excludeIp=" + ip,  // 
    	      	//data: {tel: tel},  //传送的数据
    	      	error:function(){
    	         	alert("数据传输错误");
    	      	},success: function (json) {
    	      		console.log(json);
    	      		if (json.data == 1) {
    	      			alert("删除成功！");
    	      			$(".fied").hide();
    	      			reloadTable(begintime,finishtime);
    	      		}  else {
    	      			alert("删除失败！");
    	      			
    	      		}
    	        }
    	      
    		})         
        }
        
        //重新加载当前页
        function reloadTable(begintime, finishtime){
        	var p=$("#contentList").jqGrid('getGridParam','page');//获取当前页
        	console.log("当前页："+p);
        	$('#contentList').jqGrid('setGridParam',{
        			url:'/visitor/getIpData.do?yesterday=' + finishtime + '&oneweekago=' + begintime,
        	        datatype:'json',
        	        page:p,
        	}).trigger("reloadGrid");
        }
        
        //获取今天的数据
        function getTodayIpData(){
        	$("#contentList").setGridParam({url:'/visitor/getOneIp.do?curday=' + laydate.now()
		        }).trigger("reloadGrid");
        }
        
      	//获取昨天的数据
        function getYesterdayIpData(){
        	$("#contentList").setGridParam({url:'/visitor/getOneIp.do?curday=' + laydate.now(-1)
		        }).trigger("reloadGrid");
        }
      	
        /**
        * 生成一个用不重复的ID
        */
       function GenNonDuplicateID(randomLength){
         return Number(Math.random().toString().substr(3,randomLength) + Date.now()).toString(36)
       }
        
      
      
    </script>

</html>